﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SqlPrompt
{
	class DataChunk
	{
		public List<int> ColumnLengths = new List<int>();
		public List<List<string>> Data = new List<List<string>>();

		public void Reset()
		{
			ColumnLengths.Clear();
			Data.Clear();
		}

		public void NewRow()
		{
			Data.Add(new List<string>());
		}

		public void AddField(string fieldValue)
		{
			int currentRowIndex = Data.Count - 1;

			var row = Data[currentRowIndex];
			row.Add(fieldValue);

			int currentFieldIndex = row.Count - 1;
			var field = row[currentFieldIndex];

			if (currentFieldIndex >= ColumnLengths.Count)
			{
				ColumnLengths.Add(field.Length);
			}
			else if (field.Length > ColumnLengths[currentFieldIndex])
			{
				ColumnLengths[currentFieldIndex] = field.Length;
			}
		}

		public int NumberOfRows { get { return Data.Count; } }
	}
}
